package Waya::Property::Label;

use warnings;
use strict;
use Waya::Coordinate;

use base 'Waya::Property';

__PACKAGE__
    ->mk_scalar_accessors(qw(label))
    ->mk_object_accessors(
        'Waya::Coordinate' => 'coord',
    );


# accept something like 'ac:b' and set coordinates to 'ac', label to 'b'
sub set_sgf_label {
    my ($self, $sgf_label) = @_;
    my ($sgf_coord, $label) = split /:/ => $sgf_label;
    $self->coord(Waya::Coordinate->new_from_sgf_coordinate($sgf_coord));
    $self->label($label);
}


sub new_from_sgf_label {
    my ($class, $label) = @_;
    my $self = $class->new;
    $self->set_sgf_label($label);
    $self;
}


# Provide a default value for the label when we write it out again. Sometimes
# files have things like LB[ab:1][cc][de], which doesn't make sense - we just
# assume that the given points are to be marked with something, and use 'x'
# for that.

sub to_sgf {
    my $self = shift;
    join ':' => $self->coord, ($self->label || 'x');
}


1;
